using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using AnimalFarm.Quarantine_manage;
using BO;
using BL;
using Telerik.WinControls.UI;
namespace AnimalFarm.Quarantine_manage
{

    
    public partial class UpdateQuarantine : Telerik.WinControls.UI.RadForm
    {
        DataTable quarantineData;
        B_Quarantine quarantineManager;
        Quarantine_Info selectedQuarantine;
        public UpdateQuarantine()
        {
            InitializeComponent();
            quarantineManager = B_Quarantine.CreateInstance();
            bindQuarantineData();
        }
        public void bindQuarantineData()
        {
            quarantineData = quarantineManager.GetAllQuarantine();
            grid_quarantine.DataSource = quarantineData;

        }
        public Quarantine_Info convertRowToQuarantine(GridViewRowInfo row)
        {
            Quarantine_Info quarantine = new Quarantine_Info();
            quarantine.QuarantineID = int.Parse(row.Cells["QuarantineID"].Value.ToString());
            quarantine.LivestockID = int.Parse(row.Cells["LivestockID"].Value.ToString());
            quarantine.QuarantineDate =(DateTime) row.Cells["QuarantineDate"].Value;
            quarantine.QuarantinePlaceID = int.Parse(row.Cells["QuarantinePlaceID"].Value.ToString());
            quarantine.QuarantineStatus =bool.Parse(row.Cells["QuarantineStatus"].Value.ToString());
            quarantine.ReleaseDate = (DateTime)row.Cells["ReleaseDate"].Value;
            quarantine.QuarantineReason = row.Cells["QuarantineReason"].Value.ToString();
            return quarantine;
        }

        private void radButton1_Click(object sender, EventArgs e)
        {
            try
            {
                this.selectedQuarantine.ReleaseDate = dtpTime.Value;
                this.selectedQuarantine.QuarantineStatus = cm_staus.SelectedIndex == 0 ? false : true;
                bool ok = quarantineManager.EditOneQuarantine(this.selectedQuarantine);
                if (ok)
                {
                    MessageBox.Show("Updated");
                    bindQuarantineData();
                }
                else
                    MessageBox.Show("Fail");
            }
            catch (Exception ex) { }
        }
        public void bindDetailQuarantine()
        {
            cm_staus.SelectedIndex = this.selectedQuarantine.QuarantineStatus == true ? 1 : 0;

        }
        private void grid_quarantine_MouseClick(object sender, MouseEventArgs e)
        {
            if (grid_quarantine.SelectedRows.Count > 0)
            {
                GridViewRowInfo row = grid_quarantine.SelectedRows[0];
                this.selectedQuarantine = convertRowToQuarantine(row);
                bindDetailQuarantine();
            }
        }
    }
}
